

-- Namespace
	local name,mod = ...
	_G[name] = nfCoreLib:new(mod)
	
	mod.name = name
	mod.path = 'Interface\\AddOns\\'..name..'\\'


-- Static
	mod.regions = {}


-- Unit resolution helper
	local units = {}
	
	function mod:unit(unitid)
		local u = units[unitid]
		if u then return u end
		
		u = {
			guid = nil,
			unit = unitid,
		}
		
		setmetatable(u,{
			__call = function(self,uid)
				return uid == self.guid or uid == self.unit
			end,
		})
		
		units[unitid] = u
		
		return u
	end
	
	mod:event_register('PLAYER_ENTERING_WORLD',function()
		for unit,data in pairs(units) do
			data.guid = UnitGUID(unit) or nil
		end
	end)
	
	mod:event_register('PLAYER_TARGET_CHANGED',function()
		if units['target'] then
			units['target'].guid = UnitGUID('target') or nil
		end
		if units['targettarget'] then
			units['targettarget'].guid = UnitGUID('targettarget') or nil
		end
	end)
	
	mod:event_register('PLAYER_FOCUS_CHANGED',function()
		if units['focus'] then
			units['focus'].guid = UnitGUID('focus') or nil
		end
		if units['focustarget'] then
			units['focustarget'].guid = UnitGUID('focustarget') or nil
		end
	end)
	
	mod:event_register('UNIT_TARGET',function(unit)
		if not unit then return end
		unit = unit..'target'
		if units[unit] then
			units[unit].guid = UnitGUID(unit) or nil
		end
	end)
	
	mod:event_register('UNIT_PET',function(unit)
		if unit == 'player' then
			unit = 'pet'
		elseif unit then
			unit = unit..'pet'
		else
			return
		end
		if units[unit] then
			units[unit].guid = UnitGUID(unit) or nil
		end
	end)
	
	mod:event_register('GROUP_ROSTER_UPDATE',function()
		local unit
		for i = 1,4 do
			unit = ('party%d'):format(i)
			if units[unit] then
				units[unit].guid = UnitGUID(unit) or nil
			end
		end
	end)
	
	mod:event_register('ARENA_OPPONENT_UPDATE',function()
		local unit
		for i = 1,5 do
			unit = ('arena%d'):format(i)
			if units[unit] then
				units[unit].guid = UnitGUID(unit) or nil
			end
		end
	end)
